package com.woniuxy.auth.service.impl;

import com.hc.entity.Role;
import com.woniuxy.auth.mapper.RoleMapper;
import com.woniuxy.auth.mapper.RolePermMapper;
import com.woniuxy.auth.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName RoleServiceImpl
 * @Description
 * @Author shanshan
 * @Date 2022/10/23 8:22
 * @Version 1.0
 **/
@Service
public class RoleServiceImpl implements RoleService {

    @Autowired
    private RoleMapper roleMapper;
    @Autowired
    private RolePermMapper rolePermMapper;

    @Override
    public void add(Role role, int[] permIds) {
        roleMapper.insert(role); //增加后有roleId可使用

        //循环新增
        for(int permId : permIds) { //权限表循环
            rolePermMapper.insert(role.getId(),permId);
        }

    }

    @Override
    public Role getById(int id) {
        return roleMapper.getById(id);
    }
}